package tienmanh.gs.goldminer.sprite;

import org.andengine.entity.scene.IOnAreaTouchListener;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import tienmanh.gs.goldminer.manager.ResourcesManager;
import tienmanh.gs.goldminer.scene.MapScene;

public class MapAnimation extends AnimatedSprite implements ITouchArea{
	
	AnimatedSprite star;
	VertexBufferObjectManager vbom;
	int id;
	MapScene map;

	public MapAnimation(float pX, float pY, 
			ITiledTextureRegion pTiledTextureRegion,
			VertexBufferObjectManager pVertexBufferObjectManager , int value) {
		super(pX, pY,  pTiledTextureRegion, pVertexBufferObjectManager );
		// TODO Auto-generated constructor stub
		vbom = pVertexBufferObjectManager;
		id = value;
	}
	
	
	public void setStar(int value){
		star = new AnimatedSprite(-20, -20, ResourcesManager.getInstance().starregion, vbom);
		attachChild(star);
		if(value== -1)
		star.setVisible(false);
		else
		{
			star.setVisible(true);
		star.setCurrentTileIndex(value);
	}
	}


	public boolean onAreaTouched(TouchEvent arg1,
			float pTouchAreaLocalX, float pTouchAreaLocalY) {
		// TODO Auto-generated method stub
		
		if(MapScene.level.readLevel() >= id && arg1.getAction() == TouchEvent.ACTION_DOWN && !MapScene.isRun && id != MapScene.level.readEGoldSP()){
			MapScene.getInstace().runAnimation(id);
		}
		return super
				.onAreaTouched(arg1, pTouchAreaLocalX, pTouchAreaLocalY);
	}
	

}
